﻿using Common;

using Frontdatabase;
using Frontdatabase.Entity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace WebApi.Test
{
    [ApiController, Route("test/[controller]/[action]")]
    public class UserTestController
        (FrontDbContext _context,JwtHelper _jwtHelper)
        : ControllerBase
    {
       /// <summary>
       /// 创建几个用户
       /// </summary>
       /// <returns></returns>
        public async Task<List<User>> CreateUsers()
        {
         for (int i = 0; i < 10; i++)
            {
              var u=  new User
                {
                    NickName=$"bilibili_{i+1}",
                    Password=MD5Helper.ToMd5Str("123456",null),
                    Email=$"12345678{i}@qq.com"
                };
                _context.Add(u);
            }
         _context.SaveChanges();
            var list = await _context.Users.ToListAsync();
            return list;
        }
        [HttpGet]
        public string token()
        {
            return _jwtHelper.CreateToken(null);
        }
    }
    
}
